from django.db import models

# Create your models here.
class Menu(models.Model):

	name = models.CharField(verbose_name='菜单名',max_length=20)
	superior = models.SmallIntegerField(verbose_name='上级菜单',null=True)
	status = models.SmallIntegerField(db_column=0)
	c_time = models.DateTimeField(verbose_name='创建时间',auto_now_add=True)
	u_time = models.DateTimeField(verbose_name='修改时间',auto_now=True)
	
	class Meta:
		db_table = 'menu'
	
	def __str__(self):
		return '%s-%s' % (self.name, self.superior)
	
# 商品
class Commodity(models.Model):
	
	title = models.TextField('主标题')
	subtitle = models.TextField('副标题')
	pic = models.TextField('封面图')
	status = models.SmallIntegerField(default=0)
	priority = models.IntegerField(default=100)
	c_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
	u_time = models.DateTimeField(verbose_name='修改时间', auto_now=True)
	menu = models.ForeignKey('Menu',on_delete=models.SET_NULL,null=True,related_name='commodity')
	column = models.ForeignKey('Column',on_delete=models.SET_NULL,null=True,related_name='commodity')
	
	class Meta:
		db_table = 'commodity'
	
	def __str__(self):
		return '%s-%s' % (self.title, self.subtitle)


# 栏目
class Column(models.Model):
	name = models.CharField('栏目名', max_length=40)  # 有好货、猜你喜欢、节假日优惠
	status = models.SmallIntegerField(default=0)
	priority = models.IntegerField(default=100)  # 值越小，优先级越高
	c_time = models.DateTimeField('创建时间', auto_now_add=True)
	u_time = models.DateTimeField('修改时间', auto_now=True)
	
	class Meta:
		db_table = 'column'
	
	def __str__(self):
		return '%s' % self.name
	
# 商品详情
class CommodityInfo(models.Model):
	option_name = models.CharField(verbose_name='选项名',max_length=40)
	options = models.TextField(verbose_name='选项')
	price = models.FloatField(verbose_name='价格',null=True)
	inventory = models.IntegerField(verbose_name='库存',null=True)
	image = models.TextField(verbose_name='选项图片',null=True)
	status = models.SmallIntegerField(default=0)
	c_time = models.DateTimeField('创建时间', auto_now_add=True)
	u_time = models.DateTimeField('修改时间', auto_now=True)
	commodity = models.ForeignKey('Commodity',on_delete=models.CASCADE)
	
	class Meta:
		db_table = 'commodityinfo'
	
	def __str__(self):
		return '%s-%s' % (self.option_name,self.options)
	
# 商品详情
class CommodityImage(models.Model):
	src = models.TextField(verbose_name='图片地址',null=True)
	belong = models.SmallIntegerField(verbose_name='所属展示位置')
	status = models.SmallIntegerField(default=0)
	priority = models.IntegerField(default=100)  # 值越小，优先级越高
	c_time = models.DateTimeField('创建时间', auto_now_add=True)
	u_time = models.DateTimeField('修改时间', auto_now=True)
	commodity = models.ForeignKey('Commodity', on_delete=models.CASCADE)
	
	class Meta:
		db_table = 'commodityimage'
